package com.hwy.catering.listener;

import cn.hutool.core.bean.BeanUtil;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.hwy.catering.dto.XlsxUserDto;
import com.hwy.catering.entity.User;
import com.hwy.catering.service.UserService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * excel的公共监听器
 */
@Component
public class UserXlsxListener extends AnalysisEventListener<XlsxUserDto> {

    @Resource
    private UserService userService;

    @Override
    public void invoke(XlsxUserDto xlsxUserDto, AnalysisContext analysisContext) {
        User user = new User();
        BeanUtil.copyProperties(xlsxUserDto,user);
        userService.save(user);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {

    }
}
